<?php



	class FTAORMManyToManyWrapper extends FTAORM {
		
		function __construct(FTAManyToManyInterface $sourceObject,FTAManyToManyInterface $destinationObject,Zend_Db_Adapter_Abstract $zdb=null){
			parent::__construct($zdb);
			
			//build the table name
			//set the id's.. and dont care about the primary key..
			
			//table name.. will be autmatically made up..
			// we have a table prefix.. that all table names will have
			// eg pass_ and this is stripped from the passed in objects..
			// and the name built up.. 
			$this->destinationObject = $destinationObject;
			$this->sourceObject = $sourceObject;
			
			$this->tableName = $this->joinTableName;
			$this->tableFields = array(
				$this->sourceIdName,
				$this->destinationIdName
				
			);
			
			$this->tableRequiredFields = $this->tableFields;
			
		}
		
		function getSourceIdName(){
			return $this->sourceObject->getTableBaseName() . "_" . $this->sourceObject->primaryKey;
		}
		
		function getDestinationIdName(){
			return $this->destinationObject->getTableBaseName() . "_" . $this->destinationObject->primaryKey;
		}
		
		function getJoinTableName() {
			return $this->sourceObject->getTablePrefix() . $this->sourceObject->getTableBaseName() . "_" . $this->destinationObject->getTableBaseName();
		}
		
		function save($newPrimaryKey=null){
						
			$this->{ $this->getDestinationIdName() }  = $this->destinationObject->getPrimaryKey();
			$this->{ $this->getSourceIdName() }  = $this->sourceObject->getPrimaryKey();
			
			
			return parent::save($newPrimaryKey);
		}
	}